package com.easemob.util;

import android.util.Base64;
import java.security.MessageDigest;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class CryptoUtils
{
  Cipher cipher = null;
  Cipher decipher = null;
  public static final int ALGORIGHM_DES = 0;
  public static final int ALGORIGHM_AES = 1;
  byte[] keyBytes = { 74, 111, 104, 110, 115, 111, 110, 77, 97, 74, 105, 70, 97, 110, 103, 74, 101, 114, 118, 105, 115, 76, 105, 117, 76, 105, 117, 83, 104, 97, 111, 90 };
  String key = "TongliforniaJohnson";
  static final String HEXES = "0123456789ABCDEF";

  public void init(int paramInt)
  {
    if (paramInt == 0)
      initDES();
    else
      initAES();
  }

  public void initDES()
  {
    try
    {
      MessageDigest localMessageDigest = MessageDigest.getInstance("md5");
      byte[] arrayOfByte = localMessageDigest.digest(this.key.getBytes("utf-8"));
      this.keyBytes = Arrays.copyOf(arrayOfByte, 24);
      int i = 0;
      int j = 16;
      while (i < 8)
        this.keyBytes[(j++)] = this.keyBytes[(i++)];
      SecretKeySpec localSecretKeySpec = new SecretKeySpec(this.keyBytes, "DESede");
      IvParameterSpec localIvParameterSpec = new IvParameterSpec(new byte[8]);
      this.cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
      this.cipher.init(1, localSecretKeySpec, localIvParameterSpec);
      this.decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
      this.decipher.init(2, localSecretKeySpec, localIvParameterSpec);
      EMLog.d("encrypt", "initital for DES");
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void initAES()
  {
    try
    {
      this.cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
      SecretKeySpec localSecretKeySpec = new SecretKeySpec(this.keyBytes, "AES");
      this.cipher.init(1, localSecretKeySpec);
      this.decipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
      this.decipher.init(2, localSecretKeySpec);
      EMLog.d("encrypt", "initital for AES");
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public String encryptBase64String(String paramString)
    throws Exception
  {
    byte[] arrayOfByte = encrypt(paramString);
    return new String(Base64.encode(arrayOfByte, 0));
  }

  public String decryptBase64String(String paramString)
    throws Exception
  {
    byte[] arrayOfByte1 = Base64.decode(paramString, 0);
    byte[] arrayOfByte2 = decrypt(arrayOfByte1);
    return new String(arrayOfByte2, "UTF-8");
  }

  public byte[] encrypt(String paramString)
    throws Exception
  {
    byte[] arrayOfByte1 = paramString.getBytes("UTF-8");
    byte[] arrayOfByte2 = this.cipher.doFinal(arrayOfByte1);
    return arrayOfByte2;
  }

  public byte[] encrypt(byte[] paramArrayOfByte)
    throws Exception
  {
    return this.cipher.doFinal(paramArrayOfByte);
  }

  public byte[] decrypt(byte[] paramArrayOfByte)
    throws Exception
  {
    return this.decipher.doFinal(paramArrayOfByte);
  }

  public static String getHex(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null)
      return null;
    StringBuilder localStringBuilder = new StringBuilder(2 * paramArrayOfByte.length);
    byte[] arrayOfByte = paramArrayOfByte;
    int k = paramArrayOfByte.length;
    for (int j = 0; j < k; j++)
    {
      int i = arrayOfByte[j];
      localStringBuilder.append("0123456789ABCDEF".charAt((i & 0xF0) >> 4)).append("0123456789ABCDEF".charAt(i & 0xF));
    }
    return localStringBuilder.toString();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.util.CryptoUtils
 * JD-Core Version:    0.6.1
 */